package com.zy.qudadid.presenter;

import com.zy.qudadid.model.Res;
import com.zy.qudadid.network.Const;
import com.zy.qudadid.network.Net;
import com.zy.qudadid.presenter.base.BasePresenterImp;
import com.zy.qudadid.ui.view.IndexOrderView;

import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by ninos on 2016/9/21.
 */
public class IndexOrderPresenter extends BasePresenterImp<IndexOrderView> {
    public void acceptOrder(String data){
        Subscription subscription = Net.getService()
                .acceptOrder("infoOrderCar","acceptOrder",data)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Res>() {

                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        view.error();
                    }

                    @Override
                    public void onNext(Res res) {
                        if (res.code== Const.OK){
                            view.success();
                        }else {
                            view.error();
                        }
                    }
                });

        addSubscription(subscription);
    }


    public void changeOrderstate(String data){
//        {$api_url}/api.php?c=infoOrderCar&a=changeOrderstate&args=
        Subscription subscription = Net.getService()
                .changeOrderstate("infoOrderCar","changeOrderstate",data)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Res>() {

                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        view.error();
                    }

                    @Override
                    public void onNext(Res res) {
                        if (res.code== Const.OK){
                            view.successstate();
                        }else {
                            view.errorstate();
                        }
                    }
                });

        addSubscription(subscription);
    }
}
